home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mrjong.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  152 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int flipscreen;
  13.  
  14.  
  15. /***************************************************************************
  16.  
  17.   Convert the color PROMs. (from vidhrdw/penco.c)
  18.  
  19. ***************************************************************************/
  20. void mrjong_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  21. {
  22.     int i;
  23.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  24.     #define COLOR(gfxn, offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + (offs)])
  25.  
  26.     for (i = 0; i < Machine->drv->total_colors; i++)
  27.     {
  28.         int bit0, bit1, bit2;
  29.  
  30.         /* red component */
  31.         bit0 = (*color_prom >> 0) & 0x01;
  32.         bit1 = (*color_prom >> 1) & 0x01;
  33.         bit2 = (*color_prom >> 2) & 0x01;
  34.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  35.         /* green component */
  36.         bit0 = (*color_prom >> 3) & 0x01;
  37.         bit1 = (*color_prom >> 4) & 0x01;
  38.         bit2 = (*color_prom >> 5) & 0x01;
  39.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  40.         /* blue component */
  41.         bit0 = 0;
  42.         bit1 = (*color_prom >> 6) & 0x01;
  43.         bit2 = (*color_prom >> 7) & 0x01;
  44.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  45.  
  46.         color_prom++;
  47.     }
  48.  
  49.     color_prom += 0x10;
  50.     /* color_prom now points to the beginning of the lookup table */
  51.  
  52.     /* character lookup table */
  53.     /* sprites use the same color lookup table as characters */
  54.     for (i = 0; i < TOTAL_COLORS(0); i++)
  55.         COLOR(0, i) = *(color_prom++) & 0x0f;
  56. }
  57.  
  58.  
  59. /***************************************************************************
  60.  
  61.   Display control parameter.
  62.  
  63. ***************************************************************************/
  64. WRITE_HANDLER( mrjong_flipscreen_w )
  65. {
  66.     if (flipscreen != (data & 1))
  67.     {
  68.         flipscreen = (data & 1);
  69.         memset(dirtybuffer, 1, videoram_size);
  70.     }
  71. }
  72.  
  73.  
  74. /***************************************************************************
  75.  
  76.   Draw the game screen in the given osd_bitmap.
  77.  
  78. ***************************************************************************/
  79. void mrjong_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
  80. {
  81.     int offs;
  82.  
  83.     /* Draw the tiles. */
  84.     for (offs = (videoram_size - 1); offs > 0; offs--)
  85.     {
  86.         if (dirtybuffer[offs])
  87.         {
  88.             int tile;
  89.             int color;
  90.             int sx, sy;
  91.             int flipx, flipy;
  92.  
  93.             dirtybuffer[offs] = 0;
  94.  
  95.             tile = videoram[offs] | ((colorram[offs] & 0x20) << 3);
  96.             flipx = (colorram[offs] & 0x40) >> 6;
  97.             flipy = (colorram[offs] & 0x80) >> 7;
  98.             color = colorram[offs] & 0x1f;
  99.  
  100.             sx = 31 - (offs % 32);
  101.             sy = 31 - (offs / 32);
  102.  
  103.             if (flipscreen)
  104.             {
  105.                 sx = 31 - sx;
  106.                 sy = 31 - sy;
  107.                 flipx = !flipx;
  108.                 flipy = !flipy;
  109.             }
  110.  
  111.             drawgfx(tmpbitmap, Machine->gfx[0],
  112.                     tile,
  113.                     color,
  114.                     flipx, flipy,
  115.                     8*sx, 8*sy,
  116.                     &Machine->drv->visible_area, TRANSPARENCY_NONE, 0);
  117.         }
  118.     }
  119.     copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->drv->visible_area, TRANSPARENCY_NONE, 0);
  120.  
  121.     /* Draw the sprites. */
  122.     for (offs = (spriteram_size - 4); offs >= 0; offs -= 4)
  123.     {
  124.         int sprt;
  125.         int color;
  126.         int sx, sy;
  127.         int flipx, flipy;
  128.  
  129.         sprt = (((spriteram[offs + 1] >> 2) & 0x3f) | ((spriteram[offs + 3] & 0x20) << 1));
  130.         flipx = (spriteram[offs + 1] & 0x01) >> 0;
  131.         flipy = (spriteram[offs + 1] & 0x02) >> 1;
  132.         color = (spriteram[offs + 3] & 0x1f);
  133.  
  134.         sx = 224 - spriteram[offs + 2];
  135.         sy = spriteram[offs + 0];
  136.         if (flipscreen)
  137.         {
  138.             sx = 208 - sx;
  139.             sy = 240 - sy;
  140.             flipx = !flipx;
  141.             flipy = !flipy;
  142.         }
  143.  
  144.         drawgfx(bitmap, Machine->gfx[1],
  145.                 sprt,
  146.                 color,
  147.                 flipx, flipy,
  148.                 sx, sy,
  149.                 &Machine->drv->visible_area, TRANSPARENCY_PEN, 0);
  150.     }
  151. }
  152.